package com.dyrj.pig.controller;


import com.dyrj.base.system.user.dao.SysUserMapper;
import com.dyrj.base.system.user.model.SysUser;
import com.dyrj.base.system.user.service.SysUserService;
import com.dyrj.pig.bean.TOrder;
import com.dyrj.pig.bean.TSuborder;
import com.dyrj.pig.bean.TUser;
import com.dyrj.pig.dao.TUserMapper;
import com.dyrj.pig.service.ITSuborderService;
import com.dyrj.pig.service.TOrderService;
import com.dyrj.pig.service.TUserService;
import com.dyrj.vo.PageResultMsg;
import com.dyrj.vo.ResultMsg;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/pig/order")
public class TOrderController {
    @Resource
    private TOrderService tOrderService;
    @Resource
    private ITSuborderService itSuborderService;

    @Resource
    private TUserService tUserService;
    @Resource
    private TUserMapper tUserMapper;

    @GetMapping("/index")
    public String index(ModelMap map) {
        return "pig/index_order";
    }

    @GetMapping("/selectuser/index")
    public String selectuser_index(HttpServletRequest request, ModelMap map) {
//		if("0".equals(getUserId())){
//			map.addAttribute("dept", "nodept");
//		}else{
//			map.addAttribute("dept", "dodept");
//		}
//        Long tenantid = getTenantid();
//        List list = tDepartmentService.selectAllTreeDept(tenantid);
//        map.addAttribute("allRoles", roleService.findRoles());
        String user_flag = request.getParameter("user");
        map.addAttribute("user_flag", user_flag);

        return "pig/index_choose_user";
    }

    /**
     * @Title: table
     * @return PageInfo<SysUser>    返回类型
     */
    @GetMapping("/selectuser/table")
    @ResponseBody
    public PageResultMsg selectusertable(TUser record) {
        return tUserService.table(record);
    }

    @GetMapping("/table")
    @ResponseBody
    public PageResultMsg table(TOrder record) {
        return tOrderService.table(record);
    }

    @GetMapping("/{id}")
    @ResponseBody
    public TOrder info(@PathVariable String id) {
        return tOrderService.info(id);
    }

    @GetMapping("/edit_threeorder/{id}")
    @ResponseBody
    public TSuborder info_edit_threeorder(@PathVariable String id) {
        return tOrderService.edit_threeorder(id);
    }

    @PutMapping("/")
    @ResponseBody
    public ResultMsg update(TOrder record) {
        return tOrderService.update(record);
    }


    @PutMapping("/suborder")
    @ResponseBody
    public ResultMsg update_suborder(TSuborder record) {
        return itSuborderService.update(record);
    }

    @DeleteMapping("/{id}")
    @ResponseBody
    public ResultMsg delete(@PathVariable String id) {
        return tOrderService.delete(id);
    }

    @PostMapping("/")
    @ResponseBody
    public ResultMsg add(TOrder record) {
        return tOrderService.add(record);
    }
}
